home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
361_01
/
gadgets.txt
< prev
next >
Wrap
Text File
|
1991-09-18
|
50KB
|
1,558 lines
/* Gadgetx.lib ---> A Custom Turbo-C Library "Bag of Tricks".
*
* J.Ekwall 30 August 91
*
* Copyrighted to the Public Domain. Unlimited Distribution Authorized.
*
* User Assumes All Risks/Liabilities.
*
* Last Update: 16 September 91/EK
*/
============================================================================
The need for "Gadgets" to extend the reach of ANSI-C has spun off many
commercially available "External" Libraries, among these C-Express and
Vitamin-C. The need to freely distribute Tools limits their usefulness,
particularly in our current User-Hostile ADPE environment.
These routines are Public Domain, either home-grown, taken from other
Public Domain sources (such as C User's Croup (CUG)), taken from Publications
or lifted from Shareware and significantly modified/enhanced (nullifying
the original copyright). CUG sources are identified by their distribution
disk number, ie. [CUG-273] is "TurboC Utilities" developed By Jim Derr,
2425 Santa Cruz Ct., Santa Rosa, Ca. 95401.
========================================================================
Notes:
1. On the CRT, X ranges 1-80, Y ranges 1-25.
2. Direct Video Routines use Vpeek/Vpoke which are hardwired for
Color CGA/EGA/VGA Video RAM based at 0xB800.
-------------------------------------------------------------------------
>AnyCharacter. Pop a Query Window for an Ascii Value.
int AnyCharacter(void)
{ /* Create Any Character */
int c, ch = 0, n = 3, xx, yy;
char FootPrint[216];
/* Ask 'em */
Getxy(&xx, &yy);
MkAskBox(FootPrint, 28, 11, 26, 3, 'L', "[ ASCII Value ]",
"[ <ESC> to Cancel ]", "Enter Three Digits: ", 0x4E);
/* Catch Response, Build Character & Split */
while (n && (c = Kbq_read()) != ESC && c != CR)
if (isdigit(c)) { ch = 10 * ch + c - '0'; n--; DputChr(c, 0x4E); }
ZapAskBox(FootPrint, 28, 11, 26, 3, 'L'); Gotoxy(xx, yy); ShowCursor(1);
if (c IS ESC) return 0; else return ch & 0xFF;
}
-------------------------------------------------------------------------
>BaseName. Return a Pointer to the Name.Ext portion of a Full Path.
char *BaseName(char *FileName)
{
char *tp1;
if ((tp1 = strrchr(FileName, BKSL)) != NULL) return ++tp1;
if ((tp1 = strrchr(FileName, COLON)) != NULL) return ++tp1;
return FileName;
}
-------------------------------------------------------------------------
>Beep. Sound Tone for Specified Duration (in milliSeconds).
void Beep(unsigned int pitch, unsigned int Duration)
{ sound(pitch); delay(Duration); nosound(); }
-------------------------------------------------------------------------
>Box. Draw/Clr a Single Line Box on the Screen. [CGU-273]
void Box(int Left, int Top, int Right, int Bottom, int Fill, int Color)
/* Draw a single line box using Color & Clear it to Fill. */
{
int i;
char Lid[81];
Dwrite(Left, Top, Color, "┌"); Dwrite(Right, Top, Color, "┐");
Dwrite(Left, Bottom, Color, "└"); Dwrite(Right, Bottom, Color, "┘");
*Lid = NULL; PadRight(Lid, '─', Right - Left - 1);
Dwrite(Left+1, Top, Color, Lid); Dwrite(Left+1, Bottom, Color, Lid);
for (i= Top + 1; i < Bottom; i++) {
Dwrite(Left, i, Color, "│"); Dwrite(Right, i, Color, "│"); }
ClrBox(++Left, ++Top, --Right, --Bottom, Fill);
}
-------------------------------------------------------------------------
>CcolorSet. Change the Color of a Column of Characters. [CGU-273]
void CcolorSet(int X, int Y, int Color, int N)
{ while (N--) if (Y < 26) SetAttr(X, Y++, Color); }
-------------------------------------------------------------------------
>CgaSnowFence. Activate ReTrace Waiting on Video RAM Access.
void CgaSnowFence(void) { SnowStop++; }
-------------------------------------------------------------------------
>Clr. Clear Entire Screen to a Specified Color.
#define Clr(x) (ClrBox(1, 1, 80, 25, x))
-------------------------------------------------------------------------
>ClrTo. Clears a Row to a Specified Point.
void ClrTo(int X, int Color)
/* Clear from the current cursor location thru X. */
{
int xx, yy;
Getxy(&xx, &yy); if (X < xx) return; Scroll(xx, yy, X, yy, Color, 0, 0);
}
-------------------------------------------------------------------------
>ClrBox. Clear a Retangular Area to a Specified Color.
#define ClrBox(a,b,c,d,x) (Scroll(a, b, c, d, x, 0, 0))
-------------------------------------------------------------------------
>CursorBwd. Left Arrow Action w/ Wrap Upwards. [CGU-273]
void CursorBwd(int N)
/* Move the cursor N cols to the left */
{
int xx, yy;
Getxy(&xx, &yy);
if ((xx -= (N % 80)) < 1) { xx -= 80; if (--yy < 1) yy = 25; }
Gotoxy(xx, yy);
}
-------------------------------------------------------------------------
>CursorDn. Down Arrow Action w/ Wrap. [CGU-273]
void CursorDn(int N)
/* Move the down N rows & wrap to top if the cursor is on the last row */
{
int xx, yy;
Getxy(&xx, &yy); if ((yy += (N % 25)) > 25) yy -= 25; Gotoxy(xx, yy);
}
-------------------------------------------------------------------------
>CursorFwd. Right Arrow Action w/ Wrap Downward. [CGU-273]
void CursorFwd(int N)
/* Move the cursor N cols to the right */
{
int xx, yy;
Getxy(&xx, &yy);
if ((xx += (N % 80)) > 80) { xx = 1; if (++yy > 25) yy = 1; }
Gotoxy(xx, yy);
}
-------------------------------------------------------------------------
>CursorNL. Perform a CR/LF Action w/ Wrap. [CGU-273]
void CursorNL(int N)
/* Move the cursor to the beginning of the next row */
{
int xx, yy;
Getxy(&xx, &yy); if ((yy += (N % 25)) > 25) yy = 1; Gotoxy(0, yy);
}
-------------------------------------------------------------------------
>CursorUP. Up Arrow Aaction w/ Wrap. [CGU-273]
void CursorUP(int N)
/* Move the cursor N rows up */
{
int xx, yy;
Getxy(&xx, &yy); if ((yy -= (N % 25)) < 1) yy = 25; Gotoxy(xx, yy);
}
-------------------------------------------------------------------------
>DputChr. Direct Write a Character at Cursor w/ Update.
void DputChr(char ch, int Color)
{
int xx, yy;
Getxy(&xx, &yy); Vpoke(Vaddr(xx,yy), ch + (Color << 8)); CursorFwd(1);
}
-------------------------------------------------------------------------
>Dread. Copy N Characters to a String Starting at (X,Y).
void Dread(int X, int Y, char *Text, int N)
{
int Addr;
Addr = Vaddr(X, Y);
for (*Text = NULL; N-- && X++ < 80; *Text = NULL, Addr += 2)
*Text++ = Vpeek(Addr) & 0xFF;
}
-------------------------------------------------------------------------
>Dwrite. Paint a String at X,Y w/ Color w/ Update.
void Dwrite(int X, int Y, int Color, char *Text)
{
int addr;
Color = Color << 8; Gotoxy(X, Y); CursorFwd(strlen(Text));
for (addr = Vaddr(X, Y); *Text; addr += 2)
Vpoke(addr, (*Text++ & 0xFF) + Color);
}
-------------------------------------------------------------------------
>DwriteEnd. Dwrite w/ Pad to Fill "n" Spaces.
void DwriteEnd(int X, int Y, int Color, char *Text, int N)
{
int addr;
Color = Color << 8; Gotoxy(X, Y); CursorFwd(strlen(Text));
for (addr = Vaddr(X, Y); *Text; addr += 2, --N)
Vpoke(addr, (*Text++ | Color));
for (Color |= ' '; N--; addr += 2) Vpoke(addr, Color);
}
-------------------------------------------------------------------------
>ExpandTabs. Explode Tabs into Spaces ala X3.64/DEC/DOS.
void ExpandTabs(char *Text)
{
int i;
for (i = 0; Text[i]; i++)
if (Text[i] IS HT) {
Text[i++] = SPACE; OpenStr(Text + i, (8 - (i % 8)) % 8); }
}
-------------------------------------------------------------------------
>FileExists. TRUE if File is Found. [CGU-273]
int FileExists(char *FileName)
/* Check to see of a Find exists. RETURN 1 if exist 0 if not. */
{
struct ffblk fb;
return !findfirst(FileName, &fb, 0);
}